﻿

var employees;

$('#employeeListPage').bind('pageinit', function(event) {
	if (sessionStorage.getItem('theName') != '' )
	    {
		     getEmployeeList();
	    }
	
});

function getEmployeeList() {

     var theName = sessionStorage.getItem('theName');
	 var thePass = sessionStorage.getItem('thePass');
	 
    console.log(URLserviceDir + '/getemployees.php?name='+theName+'&thePass='+thePass);
	
	$.getJSON(URLserviceDir + '/getemployees.php?name='+theName+'&thePass='+thePass, function(data) {
		$('#employeeList li').remove();
		employees = data.items;

		$.each(employees, function(index, employee) {
			$('#employeeList').append('<li><a href="#detailsPage?id=' + employee.id + '">' +
					'<img src="' + URLDirPicture + '/' + employee.picture + '"/>' +
					'<h4>' + employee.firstName + ' ' + employee.lastName + '</h4>' +
					'<p>' + employee.title + '</p>');
		});
		$('#employeeList').listview('refresh');
	});
}